#pragma once

class CValueTable
{

    public:
        CValueTable(void);
        ~CValueTable(void);

        /**
         Get stored value
         @returns value or 'def' if not found
        **/
        int  GetValue(const CString&,int def=0);
        /**
         Get stored value
         Asserts if string is not found
        **/
        int  GetValueExists(const CString&);

        /**
         stores value
        **/
        void SetValue(const CString&, int val);

        /**
         stores value
         @return true if value was changed; false if it is identical
        **/
        bool SetValueAndAdd(const CString&, int val);

        /**
         stores value
         if value is 0  string is removed from table
        **/
        void SetValueDelete(const CString&, int val);

        INT_PTR GetValueCount() {return mstr_name.GetSize();};
        bool GetIDPair(int id, CString& name, int& value);

        void DeleteContents();
        bool Load(FILE*);
        bool Save(FILE*);

        void Append(const CStringArray&);

#ifdef _DEBUG
        virtual void AssertValid() const;
#endif //_DEBUG

        BOOL Exists(const CString&);

        CArray<int,int>* GetValueData() {return &mstr_value;};


        CValueTable& operator=(const CValueTable&);

    private:
        CStringArray mstr_name;
        CArray<int,int> mstr_value;

        void fWriteString(FILE*f, CString& str);
        CString fReadString(FILE*f);


};
